
const txtLoginId =  new FieldValidator('txtLoginId',function(val){
    if(!val){
        return '请输入账号'
    }
    const resp =  API.exists(val)
    if(resp.data){
        return '该账号已存在，请重新申请'
    }
})

const loginPwd = new FieldValidator('txtLoginPwd',function(val){
    if(!val){
        return '请输入密码'
    }
})
const form = $(".user-form")
//阻止form表单的默认事件
form.addEventListener('submit',async function(e){
    e.preventDefault()
    const yz = await FieldValidator.validator(txtLoginId,loginPwd)
    if(!yz){
        return 
    }

    const formdatar = new FormData(form);
    const dda = Object.fromEntries(formdatar.entries())  
    const aad = await API.login(dda)
    if(aad.code === 0){
        alert('登录成功')
        location.href = './index.html'
    }else{
        txtLoginId.p.innerText = '账号或密码错误';
        loginPwd.input.value = ''
    }
    
})



API.login()